//
//  AY_BookNickNamePage.m
//  AiYue
//
//  Created by boWen on 2023/10/24.
//

#import "AY_BookNickNamePage.h"

@interface AY_BookNickNamePage ()
@property (nonatomic, strong) UIView * bg_View;
@property (nonatomic, strong) UILabel * nickMessageLabel;
@property (nonatomic, strong) UITextField * nickTextField;
@end

@implementation AY_BookNickNamePage

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initWithNav];
    [self addAllSubviews];
}

- (void)initWithNav {
    self.gk_navTitle = @"昵称";
    self.view.backgroundColor = COLOR_Bg;
    self.gk_navItemRightSpace = YNUM(12);
    self.gk_navRightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(saveAction)];
}

- (void)addAllSubviews {
    
    self.nickMessageLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"请设置2~16个字符，仅支持中英文、数字" andTextColor:COLOR(@"#BFBFBF") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(12)] andLines:1 andRadius:0 andAddSubView:self.view];
    [self.nickMessageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(YNUM(12));
        make.top.equalTo(self.view).offset(YNUM(8) + GK_STATUSBAR_NAVBAR_HEIGHT);
        make.right.equalTo(self.view).offset(YNUM(-12));
        make.height.mas_equalTo(YNUM(22));
    }];
    
    self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(0) andAddSubView:self.view];
    [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.nickMessageLabel.mas_bottom).offset(YNUM(3));
        make.height.offset(YNUM(50));
    }];
    
    self.nickTextField = [[UITextField alloc]init];
    self.nickTextField.text = self.nickName;
    [self.bg_View addSubview:self.nickTextField];
    [self.nickTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bg_View).offset(YNUM(12));
        make.right.equalTo(self.bg_View).offset(YNUM(-12));
        make.centerY.equalTo(self.bg_View);
        make.height.offset(YNUM(44));
    }];
}

- (void)saveAction {
    [AYApiRequest postUserInfoUpdate:self.nickTextField.text param:@"nickName" updateType:@"1" success:^(AY_UserUpdateModel * _Nonnull pkg) {
        if([pkg.code isEqualToString:@"200"]) {
            [self.navigationController popViewControllerAnimated:YES];
        }
    } failure:^(int status, NSString * _Nonnull info) {
        ShowToast(@"亲，网络不顺畅哟~");
    }];
}

@end
